<fieldset>
	<legend>Danh sách đọc giả</legend>
	<form class="well form-search">
	    <a class="btn btn-primary" href="<?php echo $this->config->base_path; ?>/librarian/reader/create">Thêm đọc giả</a>
        <div class="right">
            <input type="text" name="q" value="<?php echo $this->q; ?>" class="input-medium search-query">
            <button type="submit" class="btn">Tìm kiếm</button>
        </div>
    </form>
    <?php if ($this->q) { ?>
    <div class="alert alert-info">Có <strong><?php echo count($this->readers); ?></strong> kết quả tìm kiếm với từ khoá: "<strong><?php echo $this->q; ?></strong>"</div>
    <?php } ?>
	<table class="table table-striped">
        <tr>        
            <th>Họ tên</th>
            <th>Mã thẻ</th>
            <th>Email</th>
            <th>Ngày sinh</th>                        
            <th>Ngày tạo</th>
            <th>Thao tác</th>
        </tr>
        <?php foreach($this->readers as $reader) { ?>
        <tr id="row-reader-id-<?php echo $reader['AccountID']; ?>">
            <td><a href="<?php echo $this->config->base_path; ?>/librarian/reader/edit/reader_id/<?php echo $reader['AccountID']; ?>"><?php echo $reader['Name']; ?></a></td>
            <td><?php echo $reader['CardID'] ? $reader['CardID'] : 'Chưa có thẻ'; ?></td>
            <td><?php echo $reader['Email']; ?></td>
            <td><?php echo date('d/m/Y', $reader['DOB']); ?></td>
            <td><?php echo date('d/m/Y H:i:s', $reader['CreateDate']); ?></td>
            <td><a href="<?php echo $this->config->base_path; ?>/librarian/reader/edit/reader_id/<?php echo $reader['AccountID']; ?>">Chỉnh sửa</a> / <a href="javascript: reader.delete(<?php echo $reader['ReaderID']; ?>)" onclick="return confirm('Bạn có chắc chắn muốn xoá đọc giả <?php echo $reader['Name']; ?>?');" >Xoá</a></td>
        </tr>
        <?php } ?>
    </table>
    <?php echo $this->pagination; ?>
</fieldset>
<script type="text/javascript">
var reader = {
    'delete' : function(ReaderID){		
            $.ajax({
                    url: config.base_path + '/librarian/reader/delete',
                    type: 'post',
                    data: {
                            ReaderID: ReaderID
                    },
                    dataType: 'json',					
                    success: function(res){
                            if (res.status == 0)
            {
                Utils.Message.Error(res.message);
            }
                            else
                            {
                                $('#row-reader-id-' + ReaderID).remove();
                            }                   
                    }
            });
    }
};
</script>